import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
// import Layout from "@/layout";
// 权限路由管理
// 1.拆分路由
// 1.1常量路由比如登录首页404
import constantRoutes from "./constantRoutes";

// 1.2异步路由，通关不同的用户角色，需要过滤筛选出的路由，称之为异步路由
import asyncRoutes from "./asyncRoutes";

// 1.3任意路由：当路径出现错误的时候重定向到404
import asyRoutes from "./asyRoutes";

// 对外暴漏这个三个路由信息
export const allRouters = { asyRoutes, asyncRoutes, constantRoutes };
// const list = constantRoutes.concat(asyncRoutes)
const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
